﻿#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "filter/gaussianFilter2D.h"

#include <vector>

using Catch::Matchers::WithinAbs;
using std::vector;

TEST_CASE("gaussianFilter2D", "[gaussianFilter2D]")
{
    vector<vector<double>> image = {
        {10, 10, 10, 10, 10},
        {10, 20, 20, 20, 10},
        {10, 20, 30, 20, 10},
        {10, 20, 20, 20, 10},
        {10, 10, 10, 10, 10}
    };

    auto filtered = gaussianFilter2D(image, 5, 1.0, true); // 使用可分离卷积

    // 高斯模糊后:
    // 5.8402 8.85877 9.89388 8.85877 5.8402
    // 8.85877 14.4546 16.6871 14.4546 8.85877
    // 9.89388 16.6871 19.5602 16.6871 9.89388
    // 8.85877 14.4546 16.6871 14.4546 8.85877
    // 5.8402 8.85877 9.89388 8.85877 5.8402
    CHECK_THAT(filtered[0][0], WithinAbs(5.84, 0.01));
    CHECK_THAT(filtered[1][1], WithinAbs(14.45, 0.01));
    CHECK_THAT(filtered[2][2], WithinAbs(19.56, 0.01));
    CHECK_THAT(filtered[3][3], WithinAbs(14.45, 0.01));
    CHECK_THAT(filtered[4][4], WithinAbs(5.84, 0.01));
}
